package com.earnings.okhttputils.utils.ui.activity.user;

import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;

import com.earnings.R;
import com.earnings.okhttputils.utils.OkHttp.OkHttpUtils;
import com.earnings.okhttputils.utils.OkHttp.utils.ToastUtils;
import com.earnings.okhttputils.utils.UrlConstant.HttpUrl;
import com.earnings.okhttputils.utils.bean.UserBankData;
import com.earnings.okhttputils.utils.god.GodLeftHandBaseActivity;
import com.earnings.okhttputils.utils.https.HttpMap;
import com.earnings.okhttputils.utils.https.HttpObjectCallback;
import com.earnings.okhttputils.utils.ui.dialog.ChooseDialog;
import com.earnings.okhttputils.utils.utils.CommonUtil;

import java.util.Map;


/*
编辑用户信息-添加银行卡
 */

public class UserEditBankAddActivity extends GodLeftHandBaseActivity implements View.OnClickListener {


    EditText phone,bankcard;
    TextView name,idcard;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int onCreateLayoutId() {
        return R.layout.activity_user_edit_bank_add;
    }

    @Override
    protected void init() {

        setTitle("添加银行卡");


      //  clearName=findViewById(R.id.clearName);
       // clearCard=findViewById(R.id.clearCard);
        if(CommonUtil.getUser().getIdcard_status().equals( "0" )){
            final ChooseDialog info=new ChooseDialog( getContext(),"检测到您尚未实名认证，是否去认证？" );
            info.setSure( "确认",new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    skipActivity(UserEditRealnameActivity.class);
                    info.dismiss();
                    finish();

                }
            }); info.setCencel( "取消",new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                   info.dismiss();
                    finish();

                }
            });
            info.show();
        }else {
            bankcard= (EditText) findViewById(R.id.bankcard);
            idcard= (TextView) findViewById(R.id.idcard);
            name= (TextView) findViewById(R.id.name);
            phone= (EditText) findViewById(R.id.phone);
            name.setText( CommonUtil.getUser().getRealname() );
            idcard.setText( CommonUtil.getUser().getIdcard() );
            findViewById( R.id.clearPhone ).setOnClickListener( this );
            findViewById( R.id.clearCard ).setOnClickListener( this );
            findViewById( R.id.sumbit ).setOnClickListener( this );
            getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE );
        }
    }




    @Override
    public void onClick(View v) {

        int i = v.getId();
        if (i == R.id.sumbit) {

            createBankCard();
            //  initStatus(true);

        } else if (i == R.id.clearPhone) {
            phone.setText( "" );

        } else if (i == R.id.clearCard) {
            bankcard.setText( "" );

        }
    }
    public void createBankCard() {
        Map map = new HttpMap(getContext());

        map.put( "account",bankcard.getText().toString() );
        map.put( "mobile",phone.getText().toString() );
        OkHttpUtils.post().url( HttpUrl.USER_BANK_ADD_URL ).params( map ).build().execute( new HttpObjectCallback<UserBankData>(  getContext()) {
            @Override
            public void onSuccess(UserBankData object, String msg) {
                ToastUtils.showToast( getContext(),msg );
                bundleData.putString( "id", object.getId());
                bundleData.putString( "bank", object.getBank()+object.getCard_type() );
                bundleData.putString( "bankcard",object.getAccount() );
                bundleData.putString( "phone", phone.getText().toString() );
                skipActivity( UserEditBankSureActivity.class );
                finish();

            }
            @Override
            public void onFail(int code, String msg) {
                ToastUtils.showToast( getContext(),msg );
            }


        } );

    }


}
